/**
 * Created by haocongshun on 2016/10/14.
 */
var contextPath = "";
var msg = '';
$(function () {
    contextPath=getContextPath();
    $("#username").blur(function () {
        checkUsername();
    });
    $("#addUserSub").click(function () {
        if($("#username").val()==""||$("#username").val()==null){
            alert("用户名不能为空！");
            return;
        }
        if(msg){
            return;
        }
        if($("#nickname").val()==""||$("#nickname").val()==null){
            alert("昵称不能为空！");
            return;
        }
        if($("#email").val()==""||$("#email").val()==null){
            alert("邮箱不能为空！");
            return;
        }
        if($("#password").val()==""||$("#password").val()==null){
            alert("密码不能为空！");
            return;
        }
        $("#addUser").submit();
    });
});
function checkUsername() {
    var data = {};
    var url = contextPath+"/userManager/checkUser.press";
    data.username = $("#username").val();
    $.ajaxSetup({
        async : false
    });
    $.post(url,data,function (result) {
        if(result.Msg){
            $("#usernameTip").html("<span style='color: red;'>用户名已被使用!</span>");
            msg=result.Msg;
        }
        else {
            $("#usernameTip").html("必填");
        }
    },"json");
}
